package com.softwinner.awbt.common;

import android.app.Application;
import android.os.Handler;

import com.softwinner.awbt.dao.DaoMaster;
import com.softwinner.awbt.dao.DaoSession;
import com.softwinner.awbt.utils.LOG;

import org.greenrobot.greendao.database.Database;


/**
 * Created by xiasj on 17-12-19.
 */

public class BTApplication extends Application {

    public static final boolean ENCRYPTED = true;
    //0~初始化 1~待机状态 2~连接中 3~连接成功 4~电话拨出 5~电话打入 6~通话中
    public static final int STATUS_INIT = 0;
    public static final int STATUS_DISCONNECTED = 1;
    public static final int STATUS_CONNECTING = 2;
    public static final int STATUS_CONNECTED = 3;
    public static final int STATUS_CALL_OUT = 4;
    public static final int STATUS_INCOMING = 5;
    public static final int STATUS_TALKING = 6;
    private DaoSession mDaoSession;
    private static BTApplication sInstance;
    private boolean isBackstage;
    private int mStatus = -1;
    private String mDeviceName;
    private String mCurrentAddress;

    @Override
    public void onCreate() {
        LOG.d("---BTApplication onCreate");
        super.onCreate();
        initDatabase();
        sInstance = this;
    }

    private void initDatabase() {
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper
                        (getApplicationContext(), ENCRYPTED ? "notes-db-encrypted" : "notes-db");
                Database db = ENCRYPTED ? helper.getEncryptedWritableDb("super-secret") : helper
                        .getWritableDb();
                mDaoSession = new DaoMaster(db).newSession();
            }
        });

    }

    public static BTApplication getInstance() {
        return sInstance;
    }

    public DaoSession getDaoSession() {
        return mDaoSession;
    }

    public boolean isBackstage() {
        return isBackstage;
    }

    public void setBackstage(boolean backstage) {
        isBackstage = backstage;
    }

    public int getStatus() {
        LOG.d("BTApplication getStatus = " + mStatus);
        return mStatus;
    }

    public void setStatus(int status) {
        LOG.d("BTApplication setStatus = " + status);
        mStatus = status;
    }

    public String getDeviceName() {
        return mDeviceName;
    }

    public void setDeviceName(String deviceName) {
        this.mDeviceName = deviceName;
    }

    public String getCurrentAddress() {
        return mCurrentAddress;
    }

    public void setCurrentAddress(String address) {
        mCurrentAddress = address;
    }
}
